<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/16
 * Time: 9:31
 */

namespace app\index\model;

use think\Db;

class Site
{
    private $name = '';
    private $id = '';
    private $code = '';

    public function setSiteInfo($name)
    {
        $this->name = $name;
        $site = DB::table('homegarden.vegetable_lng_lat')
            ->where('entityAddressName', 'like', $name)
            ->field('id, entityaddressId `code`')->find();
        $this->id = $site['id'];
        $this->code = $site['code'];
    }

    public function getID($name)
    {
        if ($this->name != $name) $this->setSiteInfo($name);
        return $this->id;
    }

    public function getCode($name)
    {
        if ($this->name != $name) $this->setSiteInfo($name);
        return $this->code;
    }
}